<script setup>
import { ref, onMounted } from 'vue'
import _axios from '../../utils/myAxios.js'
import { ElMessage } from 'element-plus'
async function updateViewCount(id) {
    let resp = await _axios.put(`/api/article/updateViewCount/${id}`)
    if (resp.data.code !== 200) {
        ElMessage({
            showClose: true,
            message: resp.data.message,
            type: 'error',
            appendTo: "#app",
        })
    }
}

async function getHotArticle() {
    let resp = await _axios.get('/api/article/getHotArticle')
    if (resp.data.code !== 200) {
        ElMessage({
            showClose: true,
            message: resp.data.message,
            type: 'error',
            appendTo: "#app",
        })
    } else {
        hotArticle.value = resp.data.data
    }
}
let hotArticle = ref([])
onMounted(() => {
    getHotArticle()
})
</script>

<template>
    <div class="contentRight">
        <div class="card">
            <img style="width: 100%" src="/src/assets/image/请别再称呼我为孤独之人.png">
        </div>

        <div class="card">
            <div class="hot-article">
                <el-tag size="large" type="success">热门文章</el-tag>
                <div class="hot-article-itme" v-for="(article, index) in hotArticle" :key="index">
                    {{ index + 1 }}、
                    <el-tooltip effect="light" :content="article.summary">
                        <a :href="'#/detailArticle?articleId=' + article.id" @click="updateViewCount(article.id)"
                            target="_blank">
                            {{ article.title }}
                        </a>
                    </el-tooltip>
                    <span>---<span style="font-weight: 600;">{{ article.viewCount }}</span>次围观</span>
                </div>
            </div>
        </div>
    </div>
</template>

<style scoped>
.hot-article {
    margin-top: 20px;
}

.el-tag {
    font-size: 16px;
}

.hot-article-itme {
    margin: 10px 0;
    padding: 0 15px;
}

.hot-article-itme a {
    font-size: 15px;
}
</style>